package com.chentongwei.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author TongWei.Chen 2018-03-06 12:49
 * @Description properties文件的工具类
 */
public final class PropertiesUtil {
    private String properiesName;

    public PropertiesUtil(String fileName) {
        this.properiesName = fileName;
    }

    public String readProperty(String key) {
        String value = "";
        InputStream is = null;
        try {
            is = PropertiesUtil.class.getClassLoader().getResourceAsStream(properiesName);
            if (null == is) {
                return value;
            }
            Properties properties = new Properties();
            properties.load(is);
            value = properties.getProperty(key);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != is) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return value;
    }
}